/**
 * @param {number[]} nums
 * @return {number[]}
 */
var sortArray = function (nums) {
  quickSort(nums)
  return nums
};
function quickSort (nums, left, right) {
  let len = nums.length
  left = left === undefined ? 0 : left
  right = right === undefined ? len - 1 : right
  if (left < right) {
    let partition = getPartition(nums, left, right)
    quickSort(nums, left, partition - 1)
    quickSort(nums, partition + 1, right)
  }
}
function getPartition (nums, left, right) {
  let pivot = left
  let index = left + 1
  for (let i = index; i <= right; i++) {
    if (nums[i] < nums[pivot]) {
      swap(nums, index, i)
      index++
    }
  }
  swap(nums, pivot, index - 1)
  return index - 1
}
function swap (nums, left, right) {
  [nums[left], nums[right]] = [nums[right], nums[left]]
}


let arr = [10, 8, 9, 5, 10, 3, 6, 2, 8, 21, 13]
console.log(sortArray(arr));

